﻿using System;
using System.Collections.Generic;
using System.Text;

namespace dotHTML.HTML {
    /// <summary>
    /// Represents an embeddable object.
    /// </summary>
    [Serializable]
    public class Object : Element {
        private ICollection<string> _archive;
        private int? _border;
        private string _classid;
        private string _codebase;
        private string _codetype;
        private string _data;
        private bool _declare;
        private Form _form;
        private int? _height;
        private string _name;
        private string _standby;
        private string _type;
        private Map _usemap;
        private int? _width;

        /// <summary>
        /// Constructs a new Object element.
        /// </summary>
        public Object() {
            _archive = new LinkedList<string>();
        }

        /// <summary>
        /// Determines URLs of archives of resources for the object.
        /// </summary>
        [Obsolete("Deprecated in HTML5.")]
        public ICollection<string> Archive {
            get { return _archive; }
        }

        /// <summary>
        /// Determines the size of the border around the object, in pixels.
        /// </summary>
        [Obsolete("Deprecated in HTML4 - use CSS instead.")]
        public int? Border {
            get { return _border; }
            set { _border = value; }
        }

        /// <summary>
        /// Determines the URL of the object's implementation.
        /// </summary>
        [Obsolete("Deprecated in HTML5 - use \"data\" instead.")]
        public string ClassID {
            get { return _classid; }
            set { _classid = value; }
        }

        /// <summary>
        /// The base path used to resolve relative URLs specified by ClassID,
        /// Data, and Archive.
        /// </summary>
        [Obsolete("Deprecated in HTML5.")]
        public string CodeBase {
            get { return _codebase; }
            set { _codebase = value; }
        }

        /// <summary>
        /// Determines the content typeof the data specified by ClassID.
        /// </summary>
        [Obsolete("Deprecated in HTML5 - use \"type\" instead.")]
        public string CodeType {
            get { return _codetype; }
            set { _codetype = value; }
        }

        /// <summary>
        /// Determines the URL of the data associated with this object.
        /// </summary>
        public string Data {
            get { return _data; }
            set { _data = value; }
        }

        /// <summary>
        /// Determines whether or not this object is a declaration object.
        /// </summary>
        [Obsolete("Deprecated in HTML5 - repeeat the <object> completely.")]
        public bool Declare {
            get { return _declare; }
            set { _declare = value; }
        }

        /// <summary>
        /// Determines the parent form of the object.
        /// </summary>
        public Form Form {
            get { return _form; }
            set { _form = value; }
        }

        /// <summary>
        /// Determines the height of the object, in pixels.
        /// </summary>
        public int? Height {
            get { return _height; }
            set { _height = value; }
        }

        /// <summary>
        /// Determines the name of the object.
        /// </summary>
        public string Name {
            get { return _name; }
            set { _name = value; }
        }

        /// <summary>
        /// Determines text to be displayed while the object is loading.
        /// </summary>
        [Obsolete("Deprecated in HTML5.")]
        public string Standby {
            get { return _standby; }
            set { _standby = value; }
        }

        /// <summary>
        /// Determines the MIME type of the object.
        /// </summary>
        public string Type {
            get { return _type; }
            set { _type = value; }
        }

        /// <summary>
        /// Determines the image map that this object is a part of.
        /// </summary>
        public Map UseMap {
            get { return _usemap; }
            set { _usemap = value; }
        }

        /// <summary>
        /// Determines the width of the object, in pixels.
        /// </summary>
        public int? Width {
            get { return _width; }
            set { _width = value; }
        }

        /// <summary>
        /// Gets a formatted string of all child elements of this element.
        /// </summary>
        /// <param name="sb">The StringBuilder to write this element's child
        /// data to.</param>
        protected override void WriteLocalAttributes(StringBuilder sb) {
            AttributeWriter.Write(sb, _archive, "archive", ' ');
            AttributeWriter.Write(sb, _border, "border");
            AttributeWriter.Write(sb, _classid, "classid");
            AttributeWriter.Write(sb, _codebase, "codebase");
            AttributeWriter.Write(sb, _codetype, "codetype");
            AttributeWriter.Write(sb, _data, "data");
            AttributeWriter.Write(sb, _declare, "declare");
            if (_form != null) {
                AttributeWriter.Write(sb, _form.ID, "form");
            }
            AttributeWriter.Write(sb, _height, "height");
            AttributeWriter.Write(sb, _name, "name");
            AttributeWriter.Write(sb, _standby, "standby");
            AttributeWriter.Write(sb, _type, "type");
            if (_usemap != null) {
                AttributeWriter.Write(sb, '#' + _usemap.ID, "usemap");
            }
            AttributeWriter.Write(sb, _width, "width");
        }
    }
}
